package com.example.service.impl;

import com.example.pojo.Resume;
import com.example.pojo.ResumeClassify;
import com.example.pojo.ResumeFocus;
import com.example.mapper.ResumeFocusMapper;
import com.example.service.IResumeFocusService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.util.DictUtils;
import com.example.vo.per.ResuSelAllPage;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 简历关注表 服务实现类
 * </p>
 *
 * @author wsl
 * @since 2022-04-19
 */
@Service
public class ResumeFocusServiceImpl extends ServiceImpl<ResumeFocusMapper, ResumeFocus> implements IResumeFocusService {

    @Autowired
    private ResumeFocusMapper rfm;

    @Autowired
    private DictUtils dictUtils;

    /**
     * 新增新查询是否存在
     * @param rf
     * @return
     */
    @Override
    public Integer selInsUpt(ResumeFocus rf) {
        rf.setCreateTime(LocalDateTime.now());
        HashMap<String, Object> map = new HashMap<>();
        map.put("resume_id",rf.getResumeId());
        List<ResumeFocus> list = rfm.selectByMap(map);
        if (!list.isEmpty()){
            Integer id = list.get(0).getResumeId();
            rf.setResumeId(id);
            return rfm.updateById(rf);
        }else{
            return rfm.insert(rf);
        }
    }

    @Override
    public PageInfo<Resume> selByAllPag(ResuSelAllPage rsap) {
        PageHelper.startPage(rsap.getPageNum(),rsap.getPageSize());
        List<Resume> list = rfm.selByAll(rsap);

        list.forEach(o->{
//            ResumeClassify resumeClassify = o.getResumeClassify();
//            String tagName = dictUtils.queryDictNameByCodeAndValue("resume_tag",resumeClassify.getTag());
//            resumeClassify.setTagName(tagName);
//
//            String futn = dictUtils.queryDictNameByCodeAndValue("follow_up_type",resumeClassify.getFollowUpType());
//            resumeClassify.setFollowUpTypeName(futn);
//
//            String tl = dictUtils.queryDictNameByCodeAndValue("t_level",resumeClassify.getTalentLevel());
//            resumeClassify.setTalentLevelName(tl);
        });
        return new PageInfo<>(list);
    }
}
